import Cookies from "js-cookie";


const cookies = {};

/**
 * @description 存储 cookie 值
 * @param {String} key cookie key
 * @param {String} value cookie value
 * @param {Object} day cookie 过期时长 单位：天
 */
cookies.set = function (key = '', value = '', day) {
    !key && new Error('请设置cookie key值')
    let expiresObj = day ? { expires: day } : {}
    Cookies.set(key, value, expiresObj);
};

/**
 * @description 拿到 cookie 值
 * @param {String} key cookie name
 */
cookies.get = function (key = 'default') {
    return Cookies.get(`${key}`);
};

/**
 * @description 拿到 cookie 全部的值
 */
cookies.getAll = function () {
    return Cookies.get();
};

/**
 * @description 删除 cookie
 * @param {String} name cookie name
 */
cookies.remove = function (key = 'default') {
    return Cookies.remove(`${key}`);
};

export default cookies;